package com.itita.player.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import com.itita.player.BookDetailActivity;
import com.itita.player.R;
import com.itita.player.pojo.Book;
import com.itita.player.pojo.BookDetail;
import com.itita.player.pojo.ListItem;

public class CallBookDetailActivityAdapter {
	
	private CallBookDetailActivityAdapter() {};
	
	private static CallBookDetailActivityAdapter instance;
	
	public static CallBookDetailActivityAdapter getInstance() {
		if(instance != null) {
			return instance;
		} else {
			instance = new CallBookDetailActivityAdapter();
			return instance;
		}
	}

	public void startActivityAdapter(Context context, ListItem listItem) {
		if (listItem != null) {
			Book book = listItem.getBook();
			startActivityAdapter(context, book);
		}
	}
	
	public void startActivityAdapter(Context context, Book book) {
		if (book != null) {
			Intent intent = new Intent();
			intent.setClass(context, BookDetailActivity.class);
			String uri = "http://www.coolting.com/iosbookstore/program/episodes?curpage=1&uid=33&pagesize=" + book.getAudioCount() + "&pid=" + book.getPid() + "&cid=" + book.getCid();
			
			BookDetail bookdetail = new BookDetail();
			bookdetail.setPid(book.getPid());
			bookdetail.setCid(book.getCid());
			bookdetail.setBookName(book.getTitle());
			bookdetail.setAuthor(book.getAuthor());
			bookdetail.setAnnouncer(book.getAnnouncer());
			bookdetail.setDesc(book.getDesc());
			bookdetail.setImgUrl(book.getPicUrl());
			bookdetail.setAudioCount(book.getAudioCount());
			if(null != book.getBitmap()) {
				bookdetail.setImage(book.getBitmap());
			} else {
				Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.home_listitem_default_iron);
				bookdetail.setImage(bitmap);
			}
			bookdetail.setUri(uri);
			intent.putExtra("booklist_item", bookdetail);
			context.startActivity(intent);
		}
	}
}
